package com.ly.demo.reference;

import java.lang.ref.SoftReference;

/**
 * @author liuyang
 * @des
 * @Version 1.0
 * @Date: 06/07/2021 15:34
 */
public class SoftReferenceTest {

    public static void main(String[] args) {
        System.out.println("开始");
        A a = new A();
        SoftReference<A> sr = new SoftReference<A>(a);
        a = null;
        if (sr != null) {
            a = sr.get();
        } else {
            a = new A();
            sr = new SoftReference<A>(a);
        }
        System.out.println("结束");
    }

    static class A {
        int[] a;

        public A() {
            a = new int[100000000];
        }
    }

}
